package com.qdsgjsfk.vision.ui;

import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.RelativeLayout;

import com.qdsgjsfk.vision.base.BaseActivity;
import com.qdsgjsfk.vision.ui.fragment.ClassFragment;

import com.qdsgjsfk.vision.R;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by HP on 2018/12/17.
 */

public class ClassActivity extends BaseActivity {

    @BindView(R.id.timeline_tablayout)
    TabLayout mTabLayout;
    @BindView(R.id.timeline_viewpager)
    ViewPager mViewPager;
    @BindView(R.id.title)
    RelativeLayout title;

    @OnClick(R.id.btn_search)
    void btn_search(){
        Bundle bundle = new Bundle();
        bundle.putString("taskId",taskId);
        startActivity( SearchStudentActivity.class,bundle);
    }

    private String taskId;

    @Override
    protected void initViews() {
        mViewPager.setAdapter(new ClassListAdapter(this, getSupportFragmentManager()));
        mTabLayout.setupWithViewPager(mViewPager);
        mTabLayout.setTabMode(TabLayout.MODE_FIXED);
        mTabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
        mViewPager.setCurrentItem(0);
        mTabLayout.getTabAt(0).select();
        title.bringToFront();
    }

    @Override
    protected void initData() {
        taskId = getIntent().getStringExtra("taskId");
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_class_list;
    }


    class ClassListAdapter extends FragmentPagerAdapter {
        private static final int PAGE_COUNT = 2;

        private Context mContext;

        public ClassListAdapter(Context context, FragmentManager fm) {
            super(fm);
            this.mContext = context;
        }

        @Override
        public Fragment getItem(int position) {
            int type;
            switch (position) {
                case 0:
                    type = 0;
                    break;
                case 1:
                    type = 1;
                    break;
                default:
                    type = -1;
                    break;
            }
            return ClassFragment.newInstance(type,taskId);
        }

        @Override
        public int getCount() {
            return PAGE_COUNT;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "待筛查";
                case 1:
                    return "已筛查";
                default:
                    return "";
            }
        }

    }

}
